import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect:'/index'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/index',
    meta:{
      requireAuth:true
    },
    name: 'index',
    component: () => import('../views/index.vue')
  },
  {
      path: '/opinionNews',
      name: 'opinionNews',
      component: () => import('../views/opinionNews.vue')
    },
    {
      path: '/hotNews',
      name: 'hotNews',
      component: () => import('../views/hotNews.vue')
    },
   
    {
      path: '/details',
      name: 'details',
      component: () => import('../views/details.vue')
    },
    {
      path: '/pdf_details',
      name: 'pdf_details',
      component: () => import('../views/pdf_details.vue')
    },
    {
      path: '/classList',
      name: 'classList',
      component: () => import('../views/classList.vue')
    },
    {
      path: '/classDetails',
      name: 'classDetails',
      component: () => import('../views/classDetails.vue')
    },
    {
      path: '/garden',
      name: 'garden',
      component: () => import('../views/garden.vue')
    },
  
    {
      path: '/laws',
      name: 'laws',
      component: () => import('../views/laws.vue')
    },
    {
      path: '/examList',
      name: 'examList',
      component: () => import('../views/examList.vue')
    },
    {
      path: '/examInfo',
      name: 'examInfo',
      component: () => import('../views/examInfo.vue')
    },
    {
      path: '/examGoing',
      name: 'examGoing',
      component: () => import('../views/examGoing.vue')
    },
    {
      path: '/examResult',
      name: 'examResult',
      component: () => import('../views/examResult.vue')
    },
    {
      path: '/topList',
      name: 'topList',
      component: () => import('../views/topList.vue')
    },
    {
      path: '/recordList',
      name: 'recordList',
      component: () => import('../views/recordList.vue')
    },
    
    {
      path: '/recordDetails',
      name: 'recordDetails',
      component: () => import('../views/recordDetails.vue')
    },
  
 
]

const router = new VueRouter({
  base:'/shuban/',//此处为打包后的文件夹名
  routes,
  mode:'history'
})

export default router

router.beforeEach((to, from, next) => {
  // console.log('topath=====>',to.path)
  let customertoken = localStorage.getItem('customertoken')
    // console.log('customertoken=====>',customertoken)
    if (!customertoken && to.path !== '/login') {
      // 若本地token不存在,则任意路由跳转的时候,重定向至login 登陆页面
      next('/login')
    } else {
      next()
    }
})

